package org.anyline.simple.compare;

import org.anyline.metadata.Table;
import org.anyline.metadata.differ.TablesDiffer;
import org.anyline.proxy.ServiceProxy;
import org.anyline.util.ConfigTable;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.LinkedHashMap;

@SpringBootApplication
public class CompareApplication {


	public static void main(String[] args){
		SpringApplication application = new SpringApplication(CompareApplication.class);
		application.run(args);

		tables();
	}
	public static  void tables(){

		ConfigTable.IS_PRINT_EXCEPTION_STACK_TRACE = true;
		LinkedHashMap<String, Table> as = ServiceProxy.metadata().tables();
		LinkedHashMap<String, Table> bs = ServiceProxy.service("pg").metadata().tables();
		//对比过程 默认忽略catalog, schema
		TablesDiffer differ = TablesDiffer.compare(as, bs);
		LinkedHashMap<String, Table> adds =  differ.getAdds();
		//由a > b
		System.out.println("添加表:");
		for(Table item:adds.values()){
			System.out.println(item);
		}
		LinkedHashMap<String, Table> updates = differ.getUpdates();
		System.out.println("修改表:");
		for(Table item:updates.values()){
			System.out.println(item);
		}
		LinkedHashMap<String, Table> drops = differ.getDrops();
		System.out.println("删除表:");
		for(Table item:drops.values()){
			System.out.println(""+item);
		}
	}
}
